package com.weiqiao.api.repository.impl;

import com.weiqiao.api.repository.ICardCommodityApiRepository;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import org.apache.commons.collections4.CollectionUtils;
import org.bson.conversions.Bson;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ChenYF
 * @Description
 * @Date 2020/7/27 17:16
 */
@Repository("CardCommodityApiRepositoryImpl")
public class CardCommodityApiRepositoryImpl extends BaseMongoDaoImpl implements ICardCommodityApiRepository {
    private static final String collectionName = "card_commodity_";

    @Override
    public List<String> findCommodityByFilterAndPage(int companyId, Bson filter, Pageable pageable) {
        return super.getListAndPage(collectionName + companyId, filter, pageable);
    }

    @Override
    public String findMaxCommissionCommodity(int companyId, Bson filter, Bson sort) {
        List<String> list = super.findFilterSortLimit(collectionName + companyId, filter, sort, 1);
        return CollectionUtils.isNotEmpty(list) ? list.get(0): "";
    }

    @Override
    public List<String> findPageList(int companyId, Bson filter, Bson sort, int skip, int limit) {
        return super.findFilterSortSkipLimit(collectionName + companyId, filter, sort, skip, limit);
    }

    @Override
    public String findCommodityDetail(int companyId, Bson filter) {
        return this.findOne(collectionName + companyId, filter);
    }

    @Override
    public List<String> getBankCard(int companyId, Bson filter, Bson sort, int skip, int limit) {
        return super.findFilterSortSkipLimit(collectionName + companyId, filter, sort, skip, limit);
    }
}
